package org.example.doc_search_spring.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.example.doc_search_spring.searcher.DocSearcher;
import org.example.doc_search_spring.searcher.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DocSearchController {
    private static DocSearcher searcher = new DocSearcher();
    private ObjectMapper objectMapper = new ObjectMapper();
    @RequestMapping("/searcher")
    public String search(@RequestParam("query")String query) throws JsonProcessingException {
       List<Result> results= searcher.search(query);
       return objectMapper.writeValueAsString(results);
    }
}
